package demoMod.stsconsole.events.exordium;

import demoMod.stsconsole.dungeons.AbstractDungeon;
import demoMod.stsconsole.events.AbstractEvent;
import demoMod.stsconsole.events.EventNode;
import demoMod.stsconsole.events.EventOption;
import demoMod.stsconsole.helpers.DamageInfo;
import demoMod.stsconsole.helpers.PromptHelper;
import demoMod.stsconsole.rooms.AbstractRoom;

public class GoopWorld extends AbstractEvent {
    public static final String ID = "GoopWorld";

    public GoopWorld() {
        super(ID);
    }

    @Override
    protected EventNode initOptions() {
        EventNode rootNode = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                if (!isActive) {
                    next.get(selectedIndex).onChooseOption(optionIndex);
                    return;
                }
                options.get(optionIndex).onChooseThisOption();
                isActive = false;
            }
        };
        rootNode.bodyText = eventStrings.get(0) + "\n\n" + eventStrings.get(1);
        rootNode.options.add(new EventOption(rootNode) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(2);
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.player.damage(new DamageInfo(11, AbstractDungeon.player, DamageInfo.DamageType.HP_LOSS));
                AbstractDungeon.player.gainGold(75);
                node.setSelectedIndex(0);
            }
        });
        rootNode.options.add(new EventOption(rootNode) {
            @Override
            public String getUpdatedDescription() {
                return String.format(eventStrings.get(3), (int) (AbstractDungeon.player.getGold() * 0.3F));
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.player.loseGold((int) (AbstractDungeon.player.getGold() * 0.3F));
                node.setSelectedIndex(1);
            }
        });

        EventNode salvage = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                updateBodyTextAfterChooseOption = false;
                options.get(optionIndex).onChooseThisOption();
            }
        };
        salvage.bodyText = eventStrings.get(4);
        salvage.options.add(new EventOption(salvage) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(6);
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.currDungeon.currMapNode.room.phase = AbstractRoom.RoomPhase.COMPLETED;
                PromptHelper.backwardPrompt();
            }
        });

        EventNode giveUp = new EventNode(this) {
            @Override
            public void onChooseOption(int optionIndex) {
                updateBodyTextAfterChooseOption = false;
                options.get(optionIndex).onChooseThisOption();
            }
        };
        giveUp.bodyText = eventStrings.get(5);
        giveUp.options.add(new EventOption(giveUp) {
            @Override
            public String getUpdatedDescription() {
                return eventStrings.get(6);
            }

            @Override
            public void onChooseThisOption() {
                AbstractDungeon.currDungeon.currMapNode.room.phase = AbstractRoom.RoomPhase.COMPLETED;
                PromptHelper.backwardPrompt();
            }
        });

        rootNode.next.add(salvage);
        rootNode.next.add(giveUp);
        return rootNode;
    }
}
